package com.yt.user.api.cms;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.yt.common.constant.Result;
import com.yt.common.enums.CodeEnum;
import com.yt.common.utils.StrUtils;
import com.yt.user.models.service.ILoginInfoService;
import com.yt.user.models.vo.MaintainerInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.BeanUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import com.yt.user.models.service.IMaintainerInfoService;
import com.yt.user.models.bo.MaintainerInfoSaveBO;
import com.yt.user.models.bo.MaintainerInfoBO;
import com.yt.user.models.dto.MaintainerInfoDTO;

/**
 * 维修人员信息控制器
 *
 * @author zhou
 * @Date 2025-10-27 13:53:30
 */

@RestController
@RequestMapping("/cms/maintainerInfo")
@Slf4j
@Api(value = "MaintainerInfoController",tags = "维修人员信息接口")
public class MaintainerInfoController {

    @DubboReference
    private IMaintainerInfoService maintainerInfoService;
    @DubboReference
    private ILoginInfoService loginInfoService;

    @PostMapping("/delete")
    @ApiOperation(value = "根据id逻辑删除",notes = "根据id逻辑删除")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "delete", dataType = "Long")
    public Result<Boolean> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }
        MaintainerInfoDTO dto=maintainerInfoService.selectById(id);
        dto.setIsDelete(1);
        boolean flag =maintainerInfoService.updateById(dto);
        return new Result<>(flag);
    }

    @PostMapping("/updata")
    @ApiOperation(value = "更新维修人员信息",notes = "更新维修人员信息")
    public Result<Boolean> get(@RequestBody MaintainerInfoDTO maintainerInfoDTO){
        if(maintainerInfoDTO == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }
        MaintainerInfoDTO maintainerInfoDTO1 = new MaintainerInfoDTO();
        BeanUtils.copyProperties(maintainerInfoDTO,maintainerInfoDTO1);
        boolean flag = maintainerInfoService.updateById(maintainerInfoDTO1);
        return new Result<>(flag);
    }
    @ApiOperation(value = "维修人员信息列表",notes = "维修人员信息列表")
    @PostMapping("/queryInfo")
    public Result<List<MaintainerInfoVO>> query(){
        List<MaintainerInfoVO> maintainerInfoVOS = maintainerInfoService.query();

        return new Result<>(maintainerInfoVOS);
    }

    @ApiOperation(value = "新增维修人员信息",notes = "新增维修人员信息列表")
    @PostMapping("/addInfo")
    @Transactional
    public Result<Boolean> query(@RequestBody MaintainerInfoSaveBO saveBO){
        Boolean flag = maintainerInfoService.addAll(saveBO);
        return new Result<>(flag);
    }

}
